package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.common.enums.CaseDataStatus;
import cn.fintecher.pangolin.entity.mysql.QCaseInfo;
import cn.fintecher.pangolin.service.business.model.BaseQueryRequest;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.Objects;

/**
 * @Author wangxiangdong
 * @Description
 * @Date 2019/9/2 14:21
 **/
@Data
public class StopCasesRequest extends BaseQueryRequest {

    @ApiModelProperty(notes = "停催日期开始")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date stopTimeStart;

    @ApiModelProperty(notes = "停催日期结束")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date stopTimeEnd;

    public BooleanBuilder generateQueryBuilder() {
        BooleanBuilder booleanBuilder = generateBaseQueryBuilder();
        QCaseInfo caseInfo = QCaseInfo.caseInfo;
        booleanBuilder.and(caseInfo.caseDataStatus.eq(CaseDataStatus.PAUSE));
        if (Objects.nonNull(this.stopTimeStart)) {
            booleanBuilder.and(caseInfo.stopTime.goe(this.stopTimeStart));
        }
        if (Objects.nonNull(this.stopTimeEnd)) {
            booleanBuilder.and(caseInfo.stopTime.loe(new Date(this.stopTimeEnd.getTime()+ 86400000)));
        }
        return booleanBuilder;
    }

}
